package br.com.gp.util;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Random;
import java.text.ParseException;

public class TratamentoData {
	
	public static final DateFormat formatterBrazilianDate = new SimpleDateFormat("dd/MM/yyyy");
	public static final DateFormat formatterJDBCDate = new SimpleDateFormat("yyyy-MM-dd");
	
	public static final String conveterDateForString(Date date ){
		SimpleDateFormat formatBra;     
		Random ram = new Random();
	    formatBra = new SimpleDateFormat("yyyy-MM-dd_hh_mm_ss"+ram.hashCode());
	    return formatBra.format(date);   
	}
	
	public static final java.sql.Date convertDateUtilForDateSql(java.util.Date data ){
		return new java.sql.Date(data.getTime());
	}
	
	public static final String converteDateForDateJDBC(java.util.Date dtData){  
        SimpleDateFormat formatBra;     
        formatBra = new SimpleDateFormat("yyyy-MM-dd");  
        return (formatBra.format(dtData));  
	}
	
	public static final Date converteStringJDBCForDate(String date){
		 try {
			return   (Date)formatterJDBCDate.parse(date);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			return null;
		}  
	}
	
	public static final Date incrementaData(Date data,Integer quantidadeDias,Integer tipoIncremento){
		 Calendar calendar = Calendar.getInstance();  
		 calendar.setTime(data);
		   
		  calendar.add(tipoIncremento, quantidadeDias);
		  return calendar.getTime();
		   
	}
	
	public static final String converteDateForDateFrmtBrazilian(java.util.Date dtData){  
		try{
		SimpleDateFormat formatBra;     
        formatBra = new SimpleDateFormat("dd/MM/yyyy");  
        return (formatBra.format(dtData));
		} catch (Exception e) {
			// TODO Auto-generated catch block
			return null;
		}  
	}
}